<?php
namespace app\index\controller;
use think\File;
use think\Image;
use app\common\model\News;

class IndexController
{
    public function index()
    {
        $newsModel = new News();
        $newsList = $newsModel -> getAllUpNewsList(); 
        $RecommendNewsList = $newsModel -> getAllRecommendNewsList(); 
        
        $userData = cookie('userData');
        return view('index',['newsList'=>$newsList,'RecommendNewsList'=>$RecommendNewsList,'userData'=>$userData]);
    }

    public function getPageNewsList(){
        $page = trim(input('get.page',1));
        $limit = trim(input('get.limit',2));

        $newsModel = new News();
        $newsList = $newsModel->getPageUpNewsList(($page-1)*$limit, $limit);

        $count = $newsModel->getUpNewsListCount()[0]['totalCount'];

        return json(array('type'=>0,'newsList'=>$newsList,'count'=>$count,'page'=>$page,'limit'=>$limit));
    }



    public function detail(){
        $nid = input('get.nid');
        $newsModel = new News();
        $newsData = $newsModel -> getNewsById($nid)[0];

        $userData = cookie('userData');
        return view('detail',['newsData'=>$newsData,'userData'=>$userData]);
    }
}
